package com.yilin.platform.controller;

import com.yilin.platform.base_core.application.BaseController;
import com.yilin.platform.base_core.application.ReturnData;
import com.yilin.platform.base_core.interceptor.EncryptInterceptor;
import com.yilin.platform.entity.user.PlatConfigure;
import com.yilin.platform.service.IPlatConfigService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
@RequestMapping("/platform/cfg/")
public class ConfigController extends BaseController {

    @Resource
    private IPlatConfigService tmsConfigService;

    /**
     * 初始化配置
     */
    @PostMapping(value = "initTmsConfigure")
    @EncryptInterceptor
    public ReturnData<PlatConfigure> initTmsConfigure() {
        if (getLoginUser() == null) return jsonView(NO_LOGIN,"初始化失败，授权未成功！");
        PlatConfigure tmsConfigure = tmsConfigService.initTmsConfigure(getLoginUser());
        return jsonView(true, "获取成功", tmsConfigure);
    }

    /**
     * 更新配置
     */
    @PostMapping(value = "updateTmsConfigure")
    @EncryptInterceptor
    public ReturnData<PlatConfigure> updateTmsConfigure(PlatConfigure query) {
        if (getLoginUser() == null) return jsonView(NO_LOGIN,"初始化失败，授权未成功！");
        PlatConfigure tmsConfigure = tmsConfigService.updateTmsConfigure(query);
        return jsonView(true, "获取成功", tmsConfigure);
    }

}
